//
//  MYYHeadTopView.m
//  meiyinxiang
//
//  Created by 陈李飞 on 2017/10/23.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MYYHeadTopView.h"
#import "MYY_Me_Macro.h"
#import "MYXMemberMdel.h"

@interface MYYHeadTopView()
{
    UIButton *selectedBtn;
    UILabel *SubLabel1;
    UILabel *SubLabel2;
    UILabel *SubLabel3;
}

@end

@implementation MYYHeadTopView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor=[UIColor whiteColor];
        [self createItem];
        
    }
    return self;
}


- (void)createItem
{
    //  NSArray *titleArray = @[@"粉丝",@"关注",@"访客"];
    NSArray *titleArray = @[@"粉丝",@"关注"];
    
    //  NSArray *subArray = @[@"45",@"39",@"80"];
    
    CGFloat item_w = (self.frame.size.width-30) / titleArray.count;
    
    for (int i = 0; i<titleArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(item_w * i+15, 0, item_w, self.frame.size.height);
        button.tag = 10000+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIView* subView = [[UIView alloc] init];
        subView.frame =CGRectMake(0, 5, button.frame.size.width, button.frame.size.height-10);
        subView .userInteractionEnabled = NO;
        [button addSubview:subView];
        
        
        UILabel *titile = [[UILabel alloc] init];
        titile.frame =  CGRectMake(0, 0, button.frame.size.width, button.frame.size.height/2);
        titile.font = MYYFont(18.0f);
        titile.textAlignment = NSTextAlignmentCenter;
        titile.textColor = MYYtitleColor;
        titile.text = titleArray[i];
        [subView addSubview:titile];
        
        UILabel *Subtitile = [[UILabel alloc] init];
        Subtitile.frame = CGRectMake(0, button.frame.size.height/2, button.frame.size.width, button.frame.size.height/2);
        Subtitile.font = MYYFont(14.0f);
        Subtitile.textAlignment = NSTextAlignmentCenter;
        Subtitile.textColor = MYYSubColor;
        //Subtitile.text = subArray[i];
        if (i==0) {
            SubLabel1 =Subtitile;
        }else if (i==1){
            SubLabel2 =Subtitile;
        }else if (i==2){
            SubLabel3 =Subtitile;
        }
        [subView addSubview:Subtitile];
        
        [self addSubview:button];
    }
    
    
}

- (void)selectIndex:(NSInteger)index
{
    UIButton *button = (UIButton *)[self viewWithTag:index+10000];
    [self buttonClick:button];
}

- (void)buttonClick:(UIButton *)button
{
    
    if (self.buttonB) {
        self.buttonB(button.tag-10000);
    }
    
}

-(void)setMYXMemberMde:(MYXMemberMdel *)MYXMemberMde{
    _MYXMemberMde = MYXMemberMde;
    if (MYXMemberMde.fanscount.length<=0) {
        MYXMemberMde.fanscount= @"0";
    }
    if (MYXMemberMde.followscount.length<=0) {
        MYXMemberMde.followscount= @"0";
    }
    if (MYXMemberMde.visits.length<=0) {
        MYXMemberMde.visits= @"0";
    }
    
    SubLabel1.text =MYXMemberMde.fanscount;
    SubLabel2.text =MYXMemberMde.followscount;
    SubLabel3.text =MYXMemberMde.visits;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end

